package com.fr.data.core.db.handler;

import com.fr.base.core.DateUtils;
import com.fr.data.core.db.dialect.Dialect;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;

public class TimeTypeHandler
  implements SQLTypeHandler
{
  public void setValue(PreparedStatement paramPreparedStatement, int paramInt1, Object paramObject, int paramInt2, Dialect paramDialect)
    throws SQLException
  {
    if (paramObject instanceof java.sql.Date)
    {
      paramPreparedStatement.setTime(paramInt1, new Time(((java.sql.Date)paramObject).getTime()));
    }
    else if (paramObject instanceof java.util.Date)
    {
      paramPreparedStatement.setTime(paramInt1, new Time(((java.util.Date)paramObject).getTime()));
    }
    else if (paramObject instanceof Time)
    {
      paramPreparedStatement.setTime(paramInt1, (Time)paramObject);
    }
    else if (paramObject instanceof String)
    {
      java.util.Date localDate = null;
      try
      {
        localDate = DateUtils.string2Date(paramObject.toString(), true);
      }
      catch (Exception localException)
      {
        paramPreparedStatement.setNull(paramInt1, paramInt2);
        return;
      }
      if (localDate != null)
        paramPreparedStatement.setTime(paramInt1, new Time(localDate.getTime()));
      else
        paramPreparedStatement.setString(paramInt1, paramObject.toString());
    }
  }

  public Object getValue(ResultSet paramResultSet, int paramInt1, int paramInt2, Dialect paramDialect)
    throws SQLException
  {
    return paramResultSet.getTime(paramInt1);
  }
}